package com.gosophia.metadataEngine.action;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.gosophia.commons.DateTranslate;
import com.gosophia.commons.web.action.BaseSupportAction;
import com.gosophia.metadataEngine.bean.SystemDetailBean;
import com.gosophia.metadataEngine.dto.MetaDataFieldDto;
import com.gosophia.metadataEngine.dto.MetaDataTableDto;
import com.gosophia.metadataEngine.ws.MetadataEngineWebService;
/**
 * 查询业务系统详细信息
 * @author wangxinbing
 * @since 2011-05-12
 */
@Controller("GetSystemDataDetailAction")
@Scope("prototype")
public class GetSystemDataDetailAction extends BaseSupportAction{
    
	private Long id; 
	
	private Long metaDataTableId;
	
	private MetaDataTableDto metaDataTable;
	
	private List<SystemDetailBean> details = new ArrayList<SystemDetailBean>();
	@Autowired
	private MetadataEngineWebService metadataEngineWebService;
	@Override
	public String _execute() throws Exception {
		
		metaDataTable = metadataEngineWebService.findMetaDataTableById(metaDataTableId);
		//查询出所有页面显示项
		List<MetaDataFieldDto> detailShowItems = metadataEngineWebService.findDetailShowItemsByTableId(metaDataTableId);
		//查询详细信息
		Map<String,Object>  systemDetails = metadataEngineWebService.findSystemDataDetail(id, metaDataTableId);
		for(MetaDataFieldDto dto : detailShowItems){
			SystemDetailBean detail = new SystemDetailBean();
			detail.setDetailNameCN(dto.getFieldNameCN());
			detail.setDetailName(dto.getPrivateName());
			Object detailValue = systemDetails.get(dto.getPrivateName());
			if(detailValue !=null & "DATE".equalsIgnoreCase(detailValue.getClass().getSimpleName())){
				detail.setDetailValue(DateTranslate.simpleDateToString((Date)detailValue));
			}else{
				detail.setDetailValue(detailValue);
			}
			
			details.add(detail);
		}
		return SUCCESS;
	}
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
	public Long getMetaDataTableId() {
		return metaDataTableId;
	}
	public void setMetaDataTableId(Long metaDataTableId) {
		this.metaDataTableId = metaDataTableId;
	}
	public MetaDataTableDto getMetaDataTable() {
		return metaDataTable;
	}
	public void setMetaDataTable(MetaDataTableDto metaDataTable) {
		this.metaDataTable = metaDataTable;
	}
	public List<SystemDetailBean> getDetails() {
		return details;
	}
	public void setDetails(List<SystemDetailBean> details) {
		this.details = details;
	}
	
}
